package com.kai.steering.data.service.entity.vo;

import com.kai.steering.data.service.entity.domainObject.QuestionDO;
import com.kai.steering.data.service.entity.domainObject.TestDO;
import com.kai.steering.data.service.entity.domainObject.WarehouseDO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <pre>
 * 试卷 VO对象
 * </pre>
 *
 * @author kai
 * @date 2022-02-23
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ToString
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "TestVO对象", description = "试卷业务视图")
public class TestVO implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "试卷id")
    private String testId;
    @ApiModelProperty(value = "试卷名")
    private String testName;
    @ApiModelProperty(value = "管理员id或者用户id")
    private String founder;
    @ApiModelProperty(value = "对试卷的介绍")
    private String testInformation;
    @ApiModelProperty(value = "创建时间")
    private Date creationDatetime;
    @ApiModelProperty(value = "知识点 以,分割")
    private List<KnowledgeVO> knowledgeVOS;
    @ApiModelProperty(value = "题目列表")
    private List<QuestionVO> questionVOS;
    @ApiModelProperty(value = "存在0删除1")
    private Integer usable;
    @ApiModelProperty(value = "删除日期")
    private Date deleteDaLtetime;

    public TestVO(TestDO testDO) {
        this.convertTestVO(testDO);
    }

    public TestVO convertTestVO(TestDO testDO) {
        this.testId = testDO.getTestId();
        this.testName = testDO.getTestName();
        this.founder = testDO.getFounder();
        this.testInformation = testDO.getTestInformation();
        this.creationDatetime = testDO.getCreationDatetime();
        if (testDO.getKnowledgeDOs() != null) {
            this.knowledgeVOS = testDO.getKnowledgeDOs().stream().map(knowledgeDO -> {
                return new KnowledgeVO(knowledgeDO);
            }).collect(Collectors.toList());
        }
        if (testDO.getQuestions() != null) {
            this.questionVOS = testDO.getQuestions().stream().map(questionDO -> {
                return new QuestionVO(questionDO);
            }).collect(Collectors.toList());
        }

        this.usable = testDO.getUsable();
        this.deleteDaLtetime = testDO.getDeleteDatetime();
        return this;
    }

    public static List<TestVO> convertTestVO(List<TestDO> testDOs) {
        List<TestVO> collect = testDOs.stream().map(testDO -> {
            TestVO testVO = new TestVO(testDO);
            return testVO;
        }).collect(Collectors.toList());
        return collect;
    }


}